package ltd.trackan.messagecenter.send;

import org.springframework.stereotype.Component;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 判断标题为京东资产统计是否要发送
 * @author wxa
 */
@Component
public class JDPropertyIs {
    static final int BEAN = 2000;
    static final double PHONE = 11.0;
    
    public String send(String content) {
        String title = null;
        String bean = "";
        String phone = "";
        // 京豆是否大于2000
        Pattern pattern = Pattern.compile("【当前京豆】(\\d*)豆");
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()) {
            bean = matcher.group(1);
        }
        if (!bean.isEmpty() && Integer.parseInt(bean) >= BEAN) {
            title = "京豆已过两千,请及时消费";
            return title;
        }
        // 话费是否大于11.0
        Pattern pattern2 = Pattern.compile("【话费积分】(\\d*.\\d*)<br>");
        Matcher matcher2 = pattern2.matcher(content);
        while (matcher2.find()) {
            phone = matcher2.group(1);
        }
        if (!phone.isEmpty() && Double.parseDouble(phone) >= PHONE) {
            title = "话费积分满足兑换10元话费";
        }
        return title;
    }
    
}
